/**
 * VUEshop
 * ============================================================================
 * * 版权所有 2015-2027 深圳搜豹网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.vueshop.com.cn
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * $Author: 沈小白 2020-07-22 $
 */<template> 

	<view class="container">
		<view class="type-navbar">
			<block v-for="(item,index) in navList" :key="index">
				<view class="type-box">
					<view @tap="changeTab" class="type-navbar-item" :class="[typeActive==item.id?'type-item-on':'']" :data-id="item.id" :data-type="item.type"> {{item.name}}</view>
				</view>
			</block>
			
			
		</view>


		<!-- 订单 -->
		<view class="goods-container" v-if="goodsDateil.length>0||goodsDateil">
			<block v-for="(item,index) in goodsDateil" :key="index">
				<view class="goods-box" >
					<view class="goods-title">
						<view class="store-name" v-if="item.store">
							<image class="store-logo" :src="imgUrl+'cart/carnew.png'" role="img"></image>
							{{item.store.store_name}}
						</view>
						<view class="pay-status">{{item.order_status_detail}}</view>
					</view>
					<view class="order-number">订单编号:{{item.order_sn}}</view>
					<block  v-for="(item_good,index) in item.order_goods" :key="index">
						<view class="goods-cont">
							<navigator class="img-box" :url="'/pages/user/order_detail/order_detail?order_sn='+item.order_sn+'&isGroup=true'" role="navigation">
								<image class="wh100" :src="hostUrl+'/mall/goods/thumb_image?goods_id='+ item_good.goods_id+'&width=400&height=400'"
								 role="img">
								</image>
							</navigator>
							<navigator class="goods-mes" :url="'/pages/user/order_detail/order_detail?order_sn='+item.order_sn+'&isGroup=true'" role="navigation">
								<view class="goods-name">{{item_good.goods_name}}
								</view>
								<view class="goods-name"></view>
								<view class="goods-price">¥ {{item_good.goods_price.toFixed(2)}}</view>
								<view class="goods-num">数量 {{item_good.goods_num}}</view>
							</navigator>
							<view @tap="checkReturnGoodsStatus" :hidden="!(item.is_able_return&&item_good.is_send==1)" class="return-btn" data-recid="5074">申请售后</view>
						</view>
					</block>
					<view class="goods-tips">
						<view class="order-total">
							<view class="goods-total">￥{{item.goods_price.toFixed(2)}}</view>
							共{{item.goods_num}}件
						</view>
						<view class="check-btn">
							<view @tap="jumpToCart4" :hidden="!item.is_able_pay" class="order-btn order-btn-pay" :data-idx="index">立即付款</view>
							<view @tap="cancelOrder" :hidden="!(item.is_able_cancel&&item.is_able_pay==true)" class="order-btn" :data-idx="index">取消订单</view>
							<navigator :hidden="!(item.is_able_cancel&&item.is_able_pay==false)"  class="order-btn" :url="'/pages/order/refund_order/refund_order?consignee='+item.consignee+'&mobile='+item.mobile+'&orderId='+item.order_id+'&order_sn='+item.order_sn" role="navigation">取消订单
							</navigator>
							<view @tap="confirmOrder" :hidden="!item.is_able_receive" class="order-btn" :data-id="index">确认收货
							</view>
							<navigator :hidden="!item.is_able_comment" class="order-btn" url="/pages/user/comment/comment?status=0" role="navigation">评价</navigator>
							<navigator :hidden="!item.is_able_shipping" class="order-btn":url="'/pages/user/express/express?order_id='+item.order_id" role="navigation">查看物流</navigator>
						</view>
					</view>
				</view>
			</block>
		</view>
		<!-- 没有数据 -->
		<view class="no-data" v-if="!goodsDateil.length>0">

			<image class="cart-image" :src="imgUrl+'cart/cart-null.png'" role="img"></image>
			<view class="no-data-title">没有相关的数据</view>
			<navigator class="lookat" open-type="switchTab" url="../../index/index" role="navigation"> 去逛逛 </navigator>
		</view>
	</view>
</template>

<script>
	import config from "@/api/config.js";
	import common from "@/common/common.js";
	import {getOrderPage,putCancelOrder,getTheGoods} from "@/api/api.js";
	import {mapState} from 'vuex';
	export default {
		data() {
			return {
				hostUrl:config.host,
				imgUrl:config.imgUrl,
				typeActive:0,//状态
				goodsDateil:"",//数据
				total:"",//条数
				navList:[
					{name:"全部",id:0,type:""},
					{name:"待付款",id:1,type:"WAITPAY"},
					{name:"待成团",id:2,type:"WAITTEAM"},
					{name:"待发货",id:3,type:"WAITSEND"},
					{name:"待收货",id:4,type:"WAITRECEIVE"},
					{name:"待评价",id:5,type:"WAITCCOMMENT"},
					
				],
				params:{
					size:10,//大小10条
					prom_type:6,//订单类型 6为拼团订单
					type:"",//默认全部订单
				}
			};
		},
		onLoad(){
			
		},
		computed: {
			...mapState(['hasLogin'])
		},
		onShow(){
			if(this.hasLogin){
				this.getOrderPage(this.params)
			}else{
				common.toast("none","请登录",2000)
				
			}
		},
		methods:{
			//订单
			getOrderPage(params){
				getOrderPage(params).then(res=>{
					console.log(res)
					if(res){
						this.goodsDateil=res.records
						this.total=res.total
					}
				})
			},
			/*取消订单*/
			putCancelOrder(params){
				putCancelOrder(params).then(res=>{
					if(res.msg==1){
						// common.toast("none","取消成功",2000)
						this.getOrderPage(this.params)
					}
					console.log(res)
				})
			},
			/*立即付款*/
			jumpToCart4(e){
				let idx=e.currentTarget.dataset.idx
				let order_sn=this.goodsDateil[idx].order_sn;
				uni.navigateTo({
					url:`/pages/cart/cart4/cart4?order_sn=${order_sn}`
				})
			},
			//切换
			changeTab(e){
				console.log(e)
				let type=e.currentTarget.dataset.type;
				let id=e.currentTarget.dataset.id;
				
				this.typeActive=id
				this.params.type=type
				this.getOrderPage(this.params)
			},
			/*取消订单*/
			cancelOrder(e){
				let idx=e.currentTarget.dataset.idx
				let order_sn=this.goodsDateil[idx].order_sn;
				let params={
					order_sn:order_sn
				}
				// console.log(order_sn)
				this.putCancelOrder(params)
				
			},
			/*确认收货*/
			confirmOrder(e){
				console.log(e)
				let idx=e.currentTarget.dataset.id
				let order_sn=this.goodsDateil[idx].order_sn;
				// console.log(order_sn)
				let params={
					order_sn:order_sn
				}
				this.getTheGoods(params)
			},
			/*确认收货*/
			getTheGoods(params){
				getTheGoods(params).then(res=>{
					console.log(res)
					if(res.msg==1){
						this.getOrderPage(this.params)
					}
				})
			},
			onReachBottom(){//下拉加载数据
				
				if(this.goodsDateil.length===this.total){
					common.toast("none","加载完了",2000)
					 return false;
				}
				this.params.size+=9;
				if(this.hasLogin){
					this.getOrderPage(this.params)
				}
				
				
			},
		}
	}
</script>

<style lang="scss">
	/* team_order.wxss */
	.type-navbar {
		white-space: nowrap;
		display: flex;
		width: 100%;
		height: 80rpx;
		background-color: #fff;
	}

	.type-box {
		width: 25%;
		box-sizing: border-box;
		font-size: 28rpx;
		line-height: 76rpx;
		padding: 0 20rpx;
		text-align: center;
		display: inline-block;
		overflow: hidden;
	}

	.type-navbar-item {
		border-bottom: 4rpx solid #fff;
	}

	.type-item-on {
		border-bottom: 4rpx solid #ff3b3b;
	}

	.goods-container {
		display: flex;
		justify-content: space-between;
		flex-wrap: wrap;
		box-sizing: content-box;
		padding: 20rpx 0;
	}

	.goods-box {
		background-color: #fff;
		margin: 0 auto;
		padding: 0 30rpx;
		margin-bottom: 20rpx;
		font-size: 28rpx;
		width: 710rpx;
		border-radius: 10rpx;
		box-sizing: border-box;
	}

	.goods-title {
		display: flex;
		justify-content: space-between;
		align-items: center;
		height: 100rpx;
	}

	.store-logo {
		height: 30rpx;
		width: 30rpx;
		border-radius: 25%;
		margin-right: 10rpx;
		vertical-align: top;
	}

	.store-name {
		color: #666;
		font-size: 30rpx;
	}

	.order-number {
		font-size: 24rpx;
		color: #666;
		margin: 30rpx 0;
	}

	.pay-status {
		color: #ff3b3b;
	}

	.goods-cont {
		padding: 20rpx 0;
		display: flex;
		justify-content: space-between;
		position: relative;
	}

	.img-box {
		width: 180rpx;
		height: 180rpx;
	}

	.goods-mes {
		width: 450rpx;
	}

	.goods-name {
		height: 30rpx;
		margin-bottom: 16rpx;
		overflow: hidden;
		line-height: 30rpx;
		color: #333;
		word-break: keep-all;
		white-space: nowrap;
		text-overflow: ellipsis;
	}

	.goods-price {
		color: #ff3b3b;
		padding-bottom: 20rpx;
	}

	.goods-num {
		color: #999999;
		font-size: 26rpx;
	}

	.return-btn {
		color: #999999;
		position: absolute;
		right: 0;
		bottom: 0rpx;
		height: 80rpx;
		line-height: 80rpx;
	}

	.goods-tips {
		height: 60rpx;
		padding: 50rpx 0;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.order-total {
		display: flex;
		justify-content: flex-start;
		font-size: 24rpx;
		color: #333;
	}

	.goods-total {
		margin-right: 20rpx;
		color: #ff3b3b;
	}

	.order-btn {
		width: 150rpx;
		height: 60rpx;
		line-height: 60rpx;
		text-align: center;
		border: 1px solid #f3f3f3;
		margin-left: 20rpx;
		float: right;
		border-radius: 5rpx;
	}

	.order-btn-pay {
		color: #fff;
		background-color: #ff3b3b;
		border-color: #ff3b3b;
	}
</style>
